package com.marketingexpert.controller.marketingmgnt;

import java.io.PrintWriter;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.sf.json.JSONArray;

import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.Controller;

import com.marketingexpert.service.storemgnt.StoreService;
import com.marketingexpert.service.storemgnt.StoreServiceFactory;
import com.marketingexpert.service.usermgnt.UserService;
import com.taobao.api.domain.ItemCat;

public class GetItemCatagoryController implements Controller {

	private StoreServiceFactory storeServiceFactory;
	
	public ModelAndView handleRequest(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		
		response.setContentType("application/x-json;charset=GBK"); 
		response.setHeader("Pragma", "No-cache"); 
		response.setHeader("Cache-Control", "no-cache"); 
		response.setHeader("Cache-Control", "no-store"); 
		response.setDateHeader("Expires", 0);  
		PrintWriter out = response.getWriter(); 
		
		StoreService storeService = getStoreServiceFactory().getService(StoreServiceFactory.TAOBAO);
		List<ItemCat> itemCategorys = storeService.getItemCategory();
		
		JSONArray itemCatsjson = JSONArray.fromObject(itemCategorys);
		out.print(itemCatsjson);
		return null;
	}

	public StoreServiceFactory getStoreServiceFactory() {
		return storeServiceFactory;
	}

	public void setStoreServiceFactory(StoreServiceFactory storeServiceFactory) {
		this.storeServiceFactory = storeServiceFactory;
	}
}
